import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

import { addCart } from "@/network/detail.js";
export default new Vuex.Store({
  state: {
    // 存储购物车的商品数据
    shopCart: [
      {
        title: "柳丝木旗舰店",
        gid:'001',
        shopKeeper: "柳丝木旗舰店",
        shopIcon: "店铺图标",
        activity: "3.8 20点开抢，每满200减20",
        image:
          "https://s5.mogucdn.com/mlcdn/c45406/200722_198lc5dfh935l81e5gag7ag7dj5ib_640x960.jpg",
        goodsTitle: "柳丝木防晒霜水感清透",
        slected: "37,米白色",
        content: "50g",
        price: 49.9,
        ischecked:false,
      }
    ]
  },
  mutations: {
    // 加入购物车
    m_addCart(state, ncart) {
      console.log('我是mutations中方法', ncart);
      // 调用接口将数据存入数据库
      const gid = ncart;
      const userid= '张三';
      addCart(gid,userid).then(res =>{
        console.log('是否执行了？',res)
      })
      state.shopCart.push(ncart)
    }
  },
  actions: {
    a_addCart(context, payload) {
      console.log('我是actions中的方法', payload);
      context.commit('m_addCart', payload);
    }

  },
  modules: {
  }
})
